package edu.java.ishop.dao.impl;

import java.io.IOException;
import java.net.UnknownHostException;
import java.util.List;

import javax.inject.Named;

import org.springframework.beans.factory.annotation.Value;

import edu.java.ishop.acessor.SocketDatasourceAccessor;
import edu.java.ishop.dao.ProductDao;
import edu.java.ishop.model.Product;
import edu.java.ishop.model.ProductCategory;
import edu.java.ishop.utils.ApplicationConfiguration;

@Named("socket")
public class ProductSocketDao extends SocketDatasourceAccessor implements
		ProductDao {

	@Value("${socket.server.host}")
	private String socketHost; 
	
	@Value("${socket.server.port}")
	private String socketPort;
	
	public ProductSocketDao() {
		// TODO Auto-generated constructor stub
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Product> getAll() {
		Object products = null;

		try {
			products = sendRequest("getAll");
		} catch (ClassNotFoundException | IOException e) {
			throw new RuntimeException(e);
		}

		return (List<Product>) products;
	}

	@Override
	public Product getById(long Id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void save(Product item) {
		// TODO Auto-generated method stub

	}

	@Override
	public void delete(Product item) {
		// TODO Auto-generated method stub

	}

	@Override
	public Product getByCategory(ProductCategory category) {
		throw new UnsupportedOperationException("getByCategory");
	}

	@Override
	public int getPort() {
		return Integer.valueOf(socketPort);
	}

	@Override
	public String getHost() {
		return socketHost;
	}

}
